package com.imooc.schedule.raw;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
public class ProcessUserJobMain {

    public static void main(String[] args) {
        //配置zk
        ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration("localhost:2181", "elastic-job-demo");
        //连接zk
        ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
        //初始化连接
        zookeeperRegistryCenter.init();

        //配置job
        JobConfiguration jobConfiguration = JobConfiguration.newBuilder("processUserJob", 3).
                //5秒触发一次任务
                cron("0/5 * * * * ?").
                shardingItemParameters("0=server1,1=server2,2=server3").build();
        ScheduleJobBootstrap scheduleJobBootstrap = new ScheduleJobBootstrap(zookeeperRegistryCenter, new ProcessUserJob(), jobConfiguration);
        //开始调度
        scheduleJobBootstrap.schedule();
    }
}
